<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>已完成订单</title>
    <c:import url="../../header.jsp"/>
</head>
<body>
<div class="content-warp">
    <div class="screen-tab-warp">
        <ul class="screen-tab">
            <li class="active tab-switch" data-target="3"><a href="javascript:void(0)">已完结</a></li>
            <li class="tab-switch"  data-target="1"><a href="javascript:void(0)">已退单</a></li>
            <li class="tab-switch" data-target="2"><a href="javascript:void(0)">已废单</a></li>
        </ul>
    </div>
    <div id="completeOrderincloud"></div>
</div>
</div>
<c:import url="../../footer.jsp"/>
<script>
    var timeType = '${timeType}';
    var codes = '${code}';
    var tables;
    var timeout = '${TIME_OUT}';
    var completeOrder = {
        "list":sysInfo.basePath +"/all_order/all_Order_json.do",//分页数据
        "completed_wj":sysInfo.basePath +"/all_order/completed_wj.html",
        "completed_f":sysInfo.basePath +"/all_order/completed_f.html",
        "completed_t":sysInfo.basePath +"/all_order/completed_t.html",
        "timeName" : "退单时间",
        "reasonName" : "退单原因",
        "completeTd" : "RZSCORDER_STATUS06",//已退单
        "completeFd" : "RZSCORDER_STATUS08"//已废单

    };
    dggui.use(['table','select2','distpicker','dggdate'], function (){
        var select2 = dggui.select2;
        var distpicker=dggui.distpicker;
        var dggdate = dggui.dggdate;
        var table = dggui.table;

        if(!isEmpty(codes)){
            if(codes == 'RZSCORDER_STATUS06'){
                $(".screen-tab li:eq(1)").addClass("active");
                $(".screen-tab li:eq(0)").removeClass("active");
                $(".screen-tab li:eq(2)").removeClass("active");
                tuidan();
            }else if(codes == 'RZSCORDER_STATUS08'){
                $(".screen-tab li:eq(2)").addClass("active");
                $(".screen-tab li:eq(0)").removeClass("active");
                $(".screen-tab li:eq(1)").removeClass("active");
                feidan();
            }else if(codes == 'RZSCORDER_STATUS17'){
                $(".screen-tab li:eq(0)").addClass("active");
                $(".screen-tab li:eq(1)").removeClass("active");
                $(".screen-tab li:eq(2)").removeClass("active");
                wanjie();
            }
        }else{
            wanjie();
        }

        $(".screen-tab li").click(function(){
            //原本状态下选项卡的值
            var target = $(".active").attr("data-target");
            //切换选项卡样式
            $(this).addClass("active").siblings().removeClass("active");
            //获取选中元素的下标
            var index = $(this).attr("data-target");
            $("#completeState").val(index);
            if(index == 1){
                $("#hiddenType").val("0");
            }else if(index == 2){
                $("#hiddenType").val("1");
            }else{
                $("#hiddenType").val("2");
            }
            if (target != index){
                //如果不相等说明点击的不是当前，所以要重新加载
                //$("completeOrder").dataTableExtend('reload');
                if(index == 1){
                    tuidan();
                }else if(index == 2){
                    feidan();
                }else if(index == 3){
                    wanjie();
                }
            }
        });
        function tuidan() {
            $.ajax({
                url:completeOrder.completed_t,
                dataType: 'html',
                success:function(html){
                    $("#completeOrderincloud").html(html);
                    //初始化所属生产事业部
                    syb("#productOrgId");
                    select2.render({
                        placeholder: "请选择",
                        elem: $('#productOrgId'),
                        allowClear: true,
                        width: "160px"
                    });


                    // 加载部门下拉框
                    queryAllDep("#signOrg");
                    //初始化订单状态
                    /*commonTreeBookCode("#orderStatus", "RZSCORDER_STATUS", 1, 1, 1, true);
                    select2.render({
                        placeholder: "请选择",
                        allowClear: true,
                        elem: $('#orderStatus'),
                        width: "160px"
                    });*/
                    select2.render({
                        placeholder: "请选择",
                        allowClear: true,
                        elem: $('#productCode'),
                        width: "160px"
                    });
                    //初始化业务类型及产品
                    distpicker.render({
                        url: "${basePath}/rzsc/common/tree_book_list.do?code=BUS_YT_DK&type=2&level=2", // 请求地址
                        elem: '#typeCode', // 容器Id
                        type: 2,
                        placeholder: '选择业态',
                        defaultParentCode:'BUS_YT_DK',
                        callback:function () {//如果不需要选产品就把callback整个方法注释掉
                            var code = $("#typeCode .plug-in-code").val();
                            initProductCode("#productCode",code);
                            select2.render({
                                placeholder: "请选择",
                                allowClear: true,
                                elem: $('#productCode'),
                                width: "160px"
                            });
                            var produtId = $("#productCode").val();
                            initChannel("#channelCode",produtId);
                            select2.render({
                                placeholder: "请选择",
                                allowClear: true,
                                elem: $('#channelCode'),
                                width: "160px"
                            });
                        },
                        callbackClear:function () {
                            $("#productCode").find("option").remove();
                            $("#productCode").append("<option value=''>请选择</option>");
                            $("#channelCode").find("option").remove();
                            $("#channelCode").append("<option value=''>请选择</option>");
                        }
                    });
                    queryAllDep("#flowUserDep");
                    //渠道初始化
                    $('#productCode').on('change', function (e) {
                        var produtId = $("#productCode").val();
                        initChannel("#channelCode",produtId);
                        select2.render({
                            placeholder: "请选择",
                            allowClear: true,
                            elem: $('#channelCode'),
                            width: "160px"
                        });
                    });
                    //初始化流程人员
                    initUser("RZSC_FLOW_USER","role","#flowUserId");
                    select2.render({
                        placeholder: "请选择",
                        allowClear: true,
                        elem: $('#flowUserId'),
                        width: "160px"
                    });
                    //初始化签单商务
                    initUser("bus_advisor","department","#signUserId");
                    select2.render({
                        placeholder: "请选择",
                        allowClear: true,
                        elem: $('#signUserId'),
                        width: "160px"
                    });
                    //初始化退单时间
                    dggdate.render({
                        elem: '#abandonReasonTime',
                        type: 'date',
                        range: '~',
                        value: timeType,
                        isInitValue: true
                    });
                    //初始化签单时间
               /*     dggdate.render({
                        elem: '#signTime',
                        type: 'date',
                        range: '~'
                    });*/
                    //初始化接单时间
                  dggdate.render({
                        elem: '#receiveOrderDate',
                        type: 'date',
                        range: '~'
                    });
                    var opt={
                        "elem":"#completeOrdert",
                        "ajax": completeOrder.list,
                        "scrollX": "true",//是否开启横项滚动
                        "oneSelectCheck":true,//单选，同时选中复选框
                        "switchStatus": "completeOrdert",
                        //"oneSelectCheck":true,//单选，同时选中复选框
                        //"destroy": "true",
                        "fixedColumns": {//锁定列，只有开启scrollX时才生效
                            "leftColumns": 4,//左侧锁定2列
                            "rightColumns": 1//右侧锁定1列
                        },
                        "fnServerParams": function (aoData) {
                            // var moneyMax = $("#moneyMax").val().trim();
                            // var moneyMin = $("#moneyMin").val().trim();
                            //搜索条件
                            //aoData = $.extend(aoData, $("#searchForm").serializeObject());
                            //aoData = $.extend(aoData, serializeObject($("#formComplete")));
                            aoData = $.extend(aoData, {
                                // customerPhone:$("#customerPhone").val(),
                                productOrgId:$("#productOrgId").val(),
                                /*statusAttr:$("#orderStatus").val(),*/
                                typeCode:$("#typeCode .plug-in-code").val(),
                                productId:$("#productCode").val(),
                                channelId:$("#channelCode").val(),
                                flowUserId:$("#flowUserId").val(),
                                abandonReasonTime:$("#abandonReasonTime").val(),
                                // signTime:$("#signTime").val(),
                                receiveOrderDate:$("#receiveOrderDate").val(),
                                signUserId:$("#signUserId").val(),
                                searchKey:$("#searchKey").val(),
                                completeState : $('#completeState').val(),
                                signOrgOrBusId:$("#signOrg").attr("data-id"),
                                customerName:$("#customerName").val(),
                                flowUserDep: $("#flowUserDep").attr("data-id"),
                                // moneyMax:moneyMax,
                                // moneyMin:moneyMin,
                            });
                            return aoData;
                        },
                        "aoColumns": [
                            {
                                "sClass": "check-th",
                                "title": '<input type="checkbox" class="checkall">',
                                "orderable": false,
                                "render": function(data, type, full, meta) {
                                    return '<input type="checkbox" class="checkchild" name="checkchild" value="' + data + '">';
                                }
                            },
                            {
                                "title": "序号",
                                "orderable": false,
                                "render": function(data, type, full, meta) {
                                    return meta.row + 1;
                                }
                            },
                            {
                                "title": "所属生产事业部",
                                "data": "productOrgName",
                                "orderable": false,
                                "render": function(data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title": "订单编号",
                                "orderable": false,
                                "data": "orderNo",
                                "render": function (data, type, full, meta) {
                                    return ('<a href=\'javascript:void(0)\' class="dggui-link"  onclick="openBusinessDetail(\'' + full.orderNo + '\',\'' + full.orderId + '\')" /><span>' + data + '</span></a>');
                                    /*return data;*/
                                }
                            },
                            {
                                "title": "生产订单编号",
                                "orderable": false,
                                "data": "scProductOrderNo",
                                "render": function (data, type, full, meta) {
                                    var result = "";
                                    result += '<a href="javascript:;"  class="dggui-link" onclick="openOrderInfoDetail(\'' + full.scProductOrderNo + '\',\'' + full.id + '\')" /><span>' + data + '</span></a>';
                                    return result;
                                }
                            },
                            {
                                "title": "客户",
                                "orderable": false,
                                "data": "customerName",
                                "render": function (data, type, full, meta) {
                                    return emptyStringConvert(full.customerName) + '<p>' + emptyStringConvert(full.customerPhone) + '</p>';
                                }
                            },
                            {
                                "title":"合同编号",
                                "orderable": false,
                                "data": "contractNo",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title":"业务类型",
                                "orderable": false,
                                "data": "businessProductName",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title":"产品",
                                "orderable": false,
                                "data": "productName",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title":"渠道",
                                "orderable": false,
                                "data": "channelName",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                'title': '签单时间',
                                'data': "signTime",
                                "orderable": false,
                                "render": function(data, type, row, meta) {
                                    var htm =  '<div class="order-render"><p>' + data ? data : '' + '</p></div>';
                                    return htm;
                                }
                            },
                            {
                                'title': '接单时间',
                                'data': "receiveOrderDate",
                                "orderable": false,
                                "render": function(data, type, row, meta) {
                                    var htm =  '<div class="order-render"><p>' + data ? data : '' + '</p></div>';
                                    return htm;
                                }
                            },
                            {
                                "title":"签单商务/部门",
                                "orderable": false,
                                "data": "signUserName",
                                "render": function (data, type, full, meta) {
                                   /* return data ? data : '';*/
                                    return emptyStringConvert(full.signUserName) + '<p>' + emptyStringConvert(full.signUserOrgName) + '</p>';
                                }
                            },
                            /*{
                                "title":"签单部门",
                                "orderable": false,
                                "data": "signUserOrgName",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },*/
                            {
                                "title":"退单时间",
                                "orderable": false,
                                "data": "returnAbandonCompleteTime",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title":"退单原因",
                                "orderable": false,
                                "data": "abandonReason",//abandonReason(退单理由),returnAbandonCompleteTime(退单完成时间)
                                "render": function (data, type, full, meta) {
                                    var htm ='<div class="line1" title="'+data+'"><p>' + strInterception(data,10) + '</p></div>';
                                    return htm;
                                }
                            },
                            {
                                "title":"需求金额（元）",
                                "orderable": false,
                                "data": "loanAmount",
                                "render": function (data, type, full, meta) {
                                    var htm = '<div class="order-render">' +
                                    '<p><span >' +data ? data : '' + '</span></p>'+
                                        '</div>'
                                    return htm;
                                }
                            },
                            {
                                "title":"订单状态",
                                "orderable": false,
                                "data": "status",
                                "render": function (data, type, full, meta) {
                                    //return data+'<p>'+full.signUserOrgName+'</p>';
                                    return data;
                                }
                            },
                            {
                                'title': '最新备注',
                                'data': "lastRemark",
                                "orderable": false,
                                "render": function (data, type, row, meta) {
                                    return '<div class="line1" title="'+data+'"><p>' + strInterception(data,10) + '</p></div>' + '<p>'+emptyStringConvert(row.lastRemarkTime)+'</p>';
                                }
                            },
                            {
                                'title': '操作',
                                "orderable": false,
                                "render": function(data, type, row, meta) {
                                    var htm = '<a href=javascript:void(0)" class="dggui-link" onclick="remarkOrder(\''+row.id+'\',$(\'#completeOrdert\'));">备注</a>';
                                    return htm;
                                }
                            }
                        ],
                        "columnDefs": [{
                            targets: [3], //第1，2，3列
                            createdCell: function (td, cellData, rowData, row, col) {
                                /*if (rowData.orderTimeStatus == timeout) {
                                    $(td).parent().addClass("red");//订单超期
                                    return;
                                } else if (rowData.nodeTimeStatus == timeout) {//节点超期
                                    $(td).parent().addClass("green");
                                    return;
                                }*/
                            }
                        }]
                    };
                    tables = table.render(opt);
                    // 处理dataTable 异常错误信息
                    $.fn.dataTable.ext.errMode = 'none';//不抛出异常
                    tables.on( 'error.dt', function ( e, settings, techNote, message ) {
                        //dggui.dialog.errors("表格查询错误，请联系管理员", 2000);
                       if(checkEmpty(settings.jqXHR.responseJSON.error)){dggui.dialog.errors(settings.jqXHR.responseJSON.error, 2000);}
                    });
                }
            });
        }
        function feidan(){
            $.ajax({
                url:completeOrder.completed_f,
                dataType: 'html',
                success:function(html){
                    $("#completeOrderincloud").html(html);
                    //初始化所属生产事业部
                    syb("#productOrgId");
                    select2.render({
                        placeholder: "请选择",
                        elem: $('#productOrgId'),
                        allowClear: true,
                        width: "160px"
                    });
                    //初始化订单状态
                    /*commonTreeBookCode("#orderStatus", "RZSCORDER_STATUS", 1, 1, 1, true);
                    select2.render({
                        placeholder: "请选择",
                        allowClear: true,
                        elem: $('#orderStatus'),
                        width: "160px"
                    });*/
                    select2.render({
                        placeholder: "请选择",
                        allowClear: true,
                        elem: $('#productCode'),
                        width: "160px"
                    });
                    //初始化业务类型及产品
                    distpicker.render({
                        url: "${basePath}/rzsc/common/tree_book_list.do?code=BUS_YT_DK&type=2&level=2", // 请求地址
                        elem: '#typeCode', // 容器Id
                        type: 2,
                        placeholder: '选择业态',
                        defaultParentCode:'BUS_YT_DK',
                        callback:function () {//如果不需要选产品就把callback整个方法注释掉
                            var code = $("#typeCode .plug-in-code").val();
                            initProductCode("#productCode",code);
                            select2.render({
                                placeholder: "请选择",
                                allowClear: true,
                                elem: $('#productCode'),
                                width: "160px"
                            });
                        },
                        callbackClear:function () {
                            $("#productCode").find("option").remove();
                            $("#productCode").append("<option value=''>请选择</option>");
                            $("#channelCode").find("option").remove();
                            $("#channelCode").append("<option value=''>请选择</option>");
                        }
                    });
                    //渠道初始化
                    $('#productCode').on('change', function (e) {
                        var produtId = $("#productCode").val();
                        initChannel("#channelCode",produtId);
                        select2.render({
                            placeholder: "请选择",
                            allowClear: true,
                            elem: $('#channelCode'),
                            width: "160px"
                        });
                    });
                    queryAllDep("#flowUserDep");
                    //初始化流程人员
                    initUser("RZSC_FLOW_USER","role","#flowUserId");
                    select2.render({
                        placeholder: "请选择",
                        allowClear: true,
                        elem: $('#flowUserId'),
                        width: "160px"
                    });
                    // 加载部门下拉框
                    queryAllDep("#signOrg");
                    //初始化签单商务
                    initUser("bus_advisor","department","#signUserId");
                    select2.render({
                        placeholder: "请选择",
                        allowClear: true,
                        elem: $('#signUserId'),
                        width: "160px"
                    });
                    //初始化废单时间
                    dggdate.render({
                        elem: '#abandonReasonTime',
                        type: 'date',
                        range: '~',
                        value: timeType,
                        isInitValue: true
                    });
                    //初始化签单时间
                    dggdate.render({
                        elem: '#signTime',
                        type: 'date',
                        range: '~'
                    });
                    //初始化接单时间
                    dggdate.render({
                        elem: '#receiveOrderDate',
                        type: 'date',
                        range: '~'
                    });
                    var opt={
                        "elem":"#completeOrderf",
                        "ajax": completeOrder.list,
                        "scrollX": "true",//是否开启横项滚动
                        "oneSelectCheck":true,//单选，同时选中复选框
                        "switchStatus": "completeOrderf",
                        //"destroy": "true",
                        "fixedColumns": {//锁定列，只有开启scrollX时才生效
                            "leftColumns": 4,//左侧锁定2列
                            "rightColumns": 1//右侧锁定1列
                        },
                        "fnServerParams": function (aoData) {
                            // var moneyMax = $("#moneyMax").val().trim();
                            // var moneyMin = $("#moneyMin").val().trim();
                            //搜索条件
                            //aoData = $.extend(aoData, $("#searchForm").serializeObject());
                            //aoData = $.extend(aoData, serializeObject($("#formComplete")));
                            aoData = $.extend(aoData, {
                                // customerPhone:$("#customerPhone").val(),
                                productOrgId:$("#productOrgId").val(),
                                /*statusAttr:$("#orderStatus").val(),*/
                                typeCode:$("#typeCode .plug-in-code").val(),
                                productId:$("#productCode").val(),
                                channelId:$("#channelCode").val(),
                                flowUserId:$("#flowUserId").val(),
                                abandonReasonTime:$("#abandonReasonTime").val(),
                                // signTime:$("#signTime").val(),
                                receiveOrderDate:$("#receiveOrderDate").val(),
                                signUserId:$("#signUserId").val(),
                                searchKey:$("#searchKey").val(),
                                completeState : $('#completeState').val(),
                                signOrgOrBusId:$("#signOrg").attr("data-id"),
                                customerName:$("#customerName").val(),
                                flowUserDep: $("#flowUserDep").attr("data-id"),
                                // moneyMax:moneyMax,
                                // moneyMin:moneyMin,
                            });
                            return aoData;
                        },
                        "aoColumns": [
                            {
                                "sClass": "check-th",
                                "title": '<input type="checkbox" class="checkall">',
                                "orderable": false,
                                "render": function(data, type, full, meta) {
                                    return '<input type="checkbox" class="checkchild" name="checkchild" value="' + data + '">';
                                }
                            },
                            {
                                "title": "序号",
                                "orderable": false,
                                "render": function(data, type, full, meta) {
                                    return meta.row + 1;
                                }
                            },
                            {
                                "title": "所属生产事业部",
                                "data": "productOrgName",
                                "orderable": false,
                                "render": function(data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title": "订单编号",
                                "orderable": false,
                                "data": "orderNo",
                                "render": function (data, type, full, meta) {
                                    return ('<a href=\'javascript:void(0)\' class="dggui-link"  onclick="openBusinessDetail(\'' + full.orderNo + '\',\'' + full.orderId + '\')" /><span>' + data + '</span></a>');
                                    /*return data;*/
                                }
                            },
                            {
                                "title": "生产订单编号",
                                "orderable": false,
                                "data": "scProductOrderNo",
                                "render": function (data, type, full, meta) {
                                    var result = "";
                                    result += '<a href="javascript:;"  class="dggui-link" onclick="openOrderInfoDetail(\'' + full.scProductOrderNo + '\',\'' + full.id + '\')" /><span>' + data + '</span></a>';
                                    return result;
                                }
                            },
                            {
                                "title": "客户",
                                "orderable": false,
                                "data": "customerName",
                                "render": function (data, type, full, meta) {
                                    return emptyStringConvert(full.customerName) + '<p>' + emptyStringConvert(full.customerPhone) + '</p>';
                                }
                            },
                            {
                                "title":"合同编号",
                                "orderable": false,
                                "data": "contractNo",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            /*{
                                 "title":"当前完成节点",
                                 "orderable": false,
                                 "data": "latestEndNodeName",
                                 "render": function (data, type, full, meta) {
                                     return data ? data : '';
                                 }
                             },*/

                            {
                                "title":"业务类型",
                                "orderable": false,
                                "data": "businessProductName",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title":"产品",
                                "orderable": false,
                                "data": "productName",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title":"渠道",
                                "orderable": false,
                                "data": "channelName",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            /*{
                                "title":"分配时间",
                                "orderable": false,
                                "data": "allotDate",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },*/
                            {
                                'title': '签单时间',
                                'data': "signTime",
                                "orderable": false,
                                "render": function(data, type, row, meta) {
                                    var htm =  '<div class="order-render"><p>' + data ? data : '' + '</p></div>';
                                    return htm;
                                }
                            },
                            {
                                'title': '接单时间',
                                'data': "receiveOrderDate",
                                "orderable": false,
                                "render": function(data, type, row, meta) {
                                    var htm =  '<div class="order-render"><p>' + data ? data : '' + '</p></div>';
                                    return htm;
                                }
                            },
                            {
                                "title":"签单商务/部门",
                                "orderable": false,
                                "data": "signUserName",
                                "render": function (data, type, full, meta) {
                                    return emptyStringConvert(full.signUserName) + '<p>' + emptyStringConvert(full.signUserOrgName) + '</p>';
                                }
                            },
                            /*{
                                "title":"签单部门",
                                "orderable": false,
                                "data": "signUserOrgName",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },*/
                            {
                                "title":"废单时间",
                                "orderable": false,
                                "data": "returnAbandonCompleteTime",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title":"废单原因",
                                "orderable": false,
                                "data": "abandonReason",//abandonReason(退单理由),returnAbandonCompleteTime(退单完成时间)
                                "render": function (data, type, full, meta) {
                                    var htm ='<div class="line1" title="'+data+'"><p>' + strInterception(data,10) + '</p></div>';
                                    return htm;
                                }
                            },

                             /*{
                                 "title":"来源方式",
                                 "orderable": false,
                                 "data": "originCode",
                                 "render": function (data, type, full, meta) {
                                     return data ? data : '';
                                 }
                             },*/

                            {
                                "title":"需求金额（元）",
                                "orderable": false,
                                "data": "loanAmount",
                                "render": function (data, type, full, meta) {
                                    var htm = '<div class="order-render">' +
                                    '<p><span >' +data ? data : '' + '</span></p>'+
                                        '</div>'
                                    return htm;
                                }
                            },
                            {
                                "title":"订单状态",
                                "orderable": false,
                                "data": "status",
                                "render": function (data, type, full, meta) {
                                    //return data+'<p>'+full.signUserOrgName+'</p>';
                                    return data;
                                }
                            },
                            {
                                'title': '最新备注',
                                'data': "lastRemark",
                                "orderable": false,
                                "render": function (data, type, row, meta) {
                                    return '<div class="line1" title="'+data+'"><p>' + strInterception(data,10) + '</p></div>' + '<p>'+emptyStringConvert(row.lastRemarkTime)+'</p>';
                                }
                            },
                            {
                                'title': '操作',
                                "orderable": false,
                                "render": function(data, type, row, meta) {
                                    var htm = '<a href=javascript:void(0)" class="dggui-link" onclick="remarkOrder(\''+row.id+'\',$(\'#completeOrderf\'));">备注</a>';
                                    return htm;
                                }
                            }
                        ],
                        "columnDefs": [{
                            targets: [3], //第1，2，3列
                            createdCell: function (td, cellData, rowData, row, col) {
                                /*if (rowData.orderTimeStatus == timeout) {
                                    $(td).parent().addClass("red");//订单超期
                                    return;
                                } else if (rowData.nodeTimeStatus == timeout) {//节点超期
                                    $(td).parent().addClass("green");
                                    return;
                                }*/
                            }
                        }]
                    };
                    tables = table.render(opt);
                    // 处理dataTable 异常错误信息
                    $.fn.dataTable.ext.errMode = 'none';//不抛出异常
                    tables.on( 'error.dt', function ( e, settings, techNote, message ) {
                        //dggui.dialog.errors("表格查询错误，请联系管理员", 2000);
                       if(checkEmpty(settings.jqXHR.responseJSON.error)){                 dggui.dialog.errors(settings.jqXHR.responseJSON.error, 2000);             }
                    });
                }
            });
        }

        function wanjie(){
            $.ajax({
                url:completeOrder.completed_wj,
                dataType: 'html',
                success:function(html){
                    $("#completeOrderincloud").html(html);
                    //初始化所属生产事业部
                    syb("#productOrgId");
                    select2.render({
                        placeholder: "请选择",
                        elem: $('#productOrgId'),
                        allowClear: true,
                        width: "160px"
                    });
                    //初始化订单状态
                    /*commonTreeBookCode("#orderStatus", "RZSCORDER_STATUS", 1, 1, 1, true);
                    select2.render({
                        placeholder: "请选择",
                        allowClear: true,
                        elem: $('#orderStatus'),
                        width: "160px"
                    });*/
                    select2.render({
                        placeholder: "请选择",
                        allowClear: true,
                        elem: $('#productCode'),
                        width: "160px"
                    });
                    //初始化业务类型及产品
                    distpicker.render({
                        url: "${basePath}/rzsc/common/tree_book_list.do?code=BUS_YT_DK&type=2&level=2", // 请求地址
                        elem: '#typeCode', // 容器Id
                        type: 2,
                        placeholder: '选择业态',
                        defaultParentCode:'BUS_YT_DK',
                        callback:function () {//如果不需要选产品就把callback整个方法注释掉
                            var code = $("#typeCode .plug-in-code").val();
                            initProductCode("#productCode",code);
                            select2.render({
                                placeholder: "请选择",
                                allowClear: true,
                                elem: $('#productCode'),
                                width: "160px"
                            });
                        },
                        callbackClear:function () {
                            $("#productCode").find("option").remove();
                            $("#productCode").append("<option value=''>请选择</option>");
                            $("#channelCode").find("option").remove();
                            $("#channelCode").append("<option value=''>请选择</option>");
                        }
                    });
                    // 加载部门下拉框
                    queryAllDep("#signOrg");
                    //渠道初始化
                    $('#productCode').on('change', function (e) {
                        var produtId = $("#productCode").val();
                        initChannel("#channelCode",produtId);
                        select2.render({
                            placeholder: "请选择",
                            allowClear: true,
                            elem: $('#channelCode'),
                            width: "160px"
                        });
                    });
                    //初始化流程人员
                    initUser("RZSC_FLOW_USER","role","#flowUserId");
                    select2.render({
                        placeholder: "请选择",
                        allowClear: true,
                        elem: $('#flowUserId'),
                        width: "160px"
                    });
                    //初始化签单商务
                    initUser("bus_advisor","role","#signUserId");
                    select2.render({
                        placeholder: "请选择",
                        allowClear: true,
                        elem: $('#signUserId'),
                        width: "160px"
                    });
                    //初始化完结时间
                    dggdate.render({
                        elem: '#completedTime',
                        type: 'date',
                        range: '~',
                        value: timeType,
                        isInitValue: true
                    });
                    //初始化签单时间
                    // dggdate.render({
                    //     elem: '#signTime',
                    //     type: 'date',
                    //     range: '~'
                    // });
                    //初始化接单时间
                    dggdate.render({
                        elem: '#receiveOrderDate',
                        type: 'date',
                        range: '~'
                    });
                    //初始化放款时间
                    dggdate.render({
                        elem: '#loanTime',
                        type: 'date',
                        range: '~'
                    });
                    var opt={
                        "elem":"#completeOrderwj",
                        "ajax": completeOrder.list,
                        "scrollX": "true",//是否开启横项滚动
                        "oneSelectCheck":true,//单选，同时选中复选框
                        "switchStatus": "completeOrderwj",
                        //"selectCheck": false, //多选,同时选中复选框
                        //"destroy": "true",
                        "fixedColumns": {//锁定列，只有开启scrollX时才生效
                            "leftColumns": 4,//左侧锁定2列
                            "rightColumns": 1//右侧锁定1列
                        },
                        "fnServerParams": function (aoData) {
                            // var moneyMax = $("#moneyMax").val().trim();
                            // var moneyMin = $("#moneyMin").val().trim();
                            //搜索条件
                            //aoData = $.extend(aoData, $("#searchForm").serializeObject());
                            //aoData = $.extend(aoData, serializeObject($("#formComplete")));
                            aoData = $.extend(aoData, {
                                // customerPhone:$("#customerPhone").val(),
                                productOrgId:$("#productOrgId").val(),
                                /*statusAttr:$("#orderStatus").val(),*/
                                typeCode:$("#typeCode .plug-in-code").val(),
                                productId:$("#productCode").val(),
                                channelId:$("#channelCode").val(),
                                flowUserId:$("#flowUserId").val(),
                                completedTime:$("#completedTime").val(),
                                // signTime:$("#signTime").val(),
                                receiveOrderDate:$("#receiveOrderDate").val(),
                                loanTime:$("#loanTime").val(),//放款时间
                                signUserId:$("#signUserId").val(),
                                searchKey:$("#searchKey").val(),
                                completeState : $('#completeState').val(),
                                signOrgOrBusId:$("#signOrg").attr("data-id"),
                                customerName:$("#customerName").val(),
                                // moneyMax:moneyMax,
                                // moneyMin:moneyMin,
                            });
                            return aoData;
                        },
                        "aoColumns": [
                            {
                                "sClass": "check-th",
                                "title": '<input type="checkbox" class="checkall">',
                                "orderable": false,
                                "render": function(data, type, full, meta) {
                                    return '<input type="checkbox" class="checkchild" name="checkchild" value="' + data + '">';
                                }
                            },
                            {
                                "title": "序号",
                                "orderable": false,
                                "render": function(data, type, full, meta) {
                                    return meta.row + 1;
                                }
                            },
                            {
                                "title": "所属生产事业部",
                                "data": "productOrgName",
                                "orderable": false,
                                "render": function(data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title": "订单编号",
                                "orderable": false,
                                "data": "orderNo",
                                "render": function (data, type, full, meta) {
                                    return ('<a href=\'javascript:void(0)\' class="dggui-link"  onclick="openBusinessDetail(\'' + full.orderNo + '\',\'' + full.orderId + '\')" /><span>' + data + '</span></a>');
                                    /*return data;*/
                                }
                            },
                            {
                                "title": "生产订单编号",
                                "orderable": false,
                                "data": "scProductOrderNo",
                                "render": function (data, type, full, meta) {
                                    var result = "";
                                    result += '<a href="javascript:;"  class="dggui-link" onclick="openOrderInfoDetail(\'' + full.scProductOrderNo + '\',\'' + full.id + '\')" /><span>' + data + '</span></a>';
                                    return result;
                                }
                            },
                            {
                                "title": "客户",
                                "orderable": false,
                                "data": "customerName",
                                "render": function (data, type, full, meta) {
                                    return emptyStringConvert(full.customerName) + '<p>' + emptyStringConvert(full.customerPhone) + '</p>';
                                }
                            },
                            /*{
                                "title":"合同编号",
                                "orderable": false,
                                "data": "contractNo",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },*/
                            {
                                "title": "当前完成节点/时间",
                                "orderable": false,
                                "data": "latestEndNodeName",
                                "render": function (data, type, full, meta) {
                                    return emptyStringConvert(full.latestEndNodeName) + '<p>' + emptyStringConvert(full.latestEndNodeTime) + '</p>';

                                }
                            },

                            {
                                "title":"业务类型",
                                "orderable": false,
                                "data": "businessProductName",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title":"产品",
                                "orderable": false,
                                "data": "productName",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title":"渠道",
                                "orderable": false,
                                "data": "channelName",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title":"流程人员",
                                "orderable": false,
                                "data": "flowUserName",
                                "render": function (data, type, full, meta) {
                                    return data ? data+'<p>'+emptyStringConvert(full.flowUserOrgName)+'</p>': '';
                                }
                            },
                            {
                                'title': '签单时间',
                                'data': "signTime",
                                "orderable": false,
                                "render": function(data, type, row, meta) {
                                    var htm =  '<div class="order-render"><p>' + data ? data : '' + '</p></div>';
                                    return htm;
                                }
                            },
                            {
                                "title":"接单时间",
                                "orderable": false,
                                "data": "receiveOrderDate",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title":"签单商务/部门",
                                "orderable": false,
                                "data": "signUserName",
                                "render": function (data, type, full, meta) {
                                    return emptyStringConvert(full.signUserName) + '<p>' + emptyStringConvert(full.signUserOrgName) + '</p>';
                                }
                            },
                            /*{
                                "title":"签单部门",
                                "orderable": false,
                                "data": "signUserOrgName",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },*/
                            {
                                "title":"放款时间",
                                "orderable": false,
                                "data": "loanTime",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title":"完结时间",
                                "orderable": false,
                                "data": "completedTime",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title":"来源方式",
                                "orderable": false,
                                "data": "originCode",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title":"需求金额（元）",
                                "orderable": false,
                                "data": "loanAmount",
                                "render": function (data, type, full, meta) {
                                    var htm = '<div class="order-render">' +
                                    '<p><span >' +data ? data : '' + '</span></p>'+
                                        '</div>'
                                    return htm;
                                }
                            },
                            {
                                "title":"订单状态",
                                "orderable": false,
                                "data": "status",
                                "render": function (data, type, full, meta) {
                                    //return data+'<p>'+full.signUserOrgName+'</p>';
                                    return data;
                                }
                            },
                            {
                                'title': '最新备注',
                                'data': "lastRemark",
                                "orderable": false,
                                "render": function (data, type, row, meta) {
                                    return '<div class="line1" title="'+data+'"><p>' + strInterception(data,10) + '</p></div>' + '<p>'+emptyStringConvert(row.lastRemarkTime)+'</p>';
                                }
                            },
                            {
                                'title': '操作',
                                "orderable": false,
                                "render": function(data, type, row, meta) {
                                    var htm = '<a href=javascript:void(0)" class="dggui-link" onclick="remarkOrder(\''+row.id+'\',$(\'#completeOrderfk\'));">备注</a>';
                                    return htm;
                                }
                            }
                        ],
                        "columnDefs": [{
                            targets: [3], //第1，2，3列
                            createdCell: function (td, cellData, rowData, row, col) {
                                if (rowData.orderTimeStatus == timeout) {
                                    $(td).parent().addClass("red");//订单超期
                                    return;
                                } else if (rowData.nodeTimeStatus == timeout) {//节点超期
                                    $(td).parent().addClass("green");
                                    return;
                                }
                            }
                        }]
                    };
                    tables = table.render(opt);
                    // 处理dataTable 异常错误信息
                    $.fn.dataTable.ext.errMode = 'none';//不抛出异常
                    tables.on( 'error.dt', function ( e, settings, techNote, message ) {
                        //dggui.dialog.errors("表格查询错误，请联系管理员", 2000);
                       if(checkEmpty(settings.jqXHR.responseJSON.error)){
                           dggui.dialog.errors(settings.jqXHR.responseJSON.error, 2000);
                       }
                    });
                }
            });
        }



    });

    /**
     * 导出
     * */
    function excelExportCompeled(url,type) {
        var obj = new Object();
        // obj.customerPhone= $("#customerPhone").val();
        obj.productOrgId= $("#productOrgId").val();
        obj.typeCode= $("#typeCode").find(".plug-in-code").val();
        obj.productId= $("#productCode").val();
        obj.channelId=$("#channelCode").val();
        if(type == 0){
            obj.abandonReasonTime=$("#abandonReasonTime").val();
        }else{
            obj.completedTime=$("#completedTime").val();
        }
        obj.signTime=$("#signTime").val();
        obj.receiveOrderDate=$("#receiveOrderDate").val();
        obj.loanTime=$("#loanTime").val(),//放款时间
        obj.searchKey=$("#searchKey").val();
        obj.signUserId=$("#signUserId").val();
        obj.flowUserId=$("#flowUserId").val();
        obj.signOrgOrBusId=$("#signOrg").attr("data-id");//签单部门
        obj.flowUserDep=$("#flowUserDep").attr("data-id");//生产部门
        obj.customerName=$("#customerName").val();
        // obj.moneyMax=moneyMax;
        // obj.moneyMin=moneyMin;
        formSubmit(url, obj);
    }

    /**
     * 导出
     * */
    function excelExportCompeledSh(url) {
        var obj = new Object();
        obj.completedTime=$("#completedTime").val();
        if(isEmpty(obj.completedTime)){
            dggui.dialog.errors('必须选择完结时间段！');
            return
        }
        var form = $("<form></form>")
        form.attr("action", url);
        form.css('display', 'none');
        for (var key in obj) {
            if (!isEmpty(obj[key])) {
                var input = $("<input type='hidden' name='" + key + "' />");
                input.attr('value', obj[key])
                form.append(input)
            }
        }
        form.appendTo("body");
        form.submit();
    }
    //列表刷新
    function tableReload() {
        // var moneyMax = $("#moneyMax").val().trim();
        // var moneyMin = $("#moneyMin").val().trim();
        // if(!checkMoneySearch(moneyMin,moneyMax)){
        //     return false;
        // }
        tables.ajax.reload();
    }
</script>
</body>
</html>